<template>
  <div class="form">
    <el-form :inline="true" :model="searchForm">
      <el-form-item prop="out_trade_no" placeholder="订单号">
        <el-input v-model="searchForm.out_trade_no"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
  </div>
  <el-table :data="tableData.list">
    <el-table-column prop="out_trade_no" label="订单号"></el-table-column>
    <el-table-column prop="hospital_name" label="就诊医院"></el-table-column>
    <el-table-column prop="service_name" label="陪诊服务"></el-table-column>
    <el-table-column label="陪护师">
      <template #default="scope">
        <el-image width="40" height="40" :src="scope.row.companion.avatar"></el-image
      ></template>
    </el-table-column>
    <el-table-column prop="service_name" label="陪护师手机号">
      <template #default="scope">
        {{ scope.row.companion.mobile }}
      </template>
    </el-table-column>
    <el-table-column prop="price" label="总价"></el-table-column>
    <el-table-column prop="paidPrice" label="已付"></el-table-column>
    <el-table-column prop="service_name" label="下单时间">
      <template #default="scope">
        {{ dayjs(order_start_time).format("YYYY-MM-DD") }}
      </template>
    </el-table-column>
    <el-table-column prop="service_name" label="订单状态">
      <template #default="scope">
        <el-tag :type="stateMap(scope.row.trade_state)">{{
          scope.row.trade_state
        }}</el-tag>
      </template>
    </el-table-column>
    <el-table-column prop="service_state" label="接单状态"></el-table-column>
    <el-table-column prop="tel" label="联系人手机号"></el-table-column>
    <el-table-column label="操作">
      <template #default="scope">
        <el-popconfirm
          v-if="scope.row.trade_state === '待服务'"
          confirm-button-text="是"
          cancel-button-text="否"
          :icon="InfoFilled"
          icon-color="#626AEF"
          title="是否确认完成?"
          @confirm="confirmEvent"
          @cancel="cancelEvent"
        >
          <el-button type="primary" link>服务完成</el-button>
        </el-popconfirm>

        <el-button type="primary" link disabled v-else>暂无服务</el-button>
      </template>
    </el-table-column>
  </el-table>
  <!-- 分页 -->
  <div class="pagination-info">
    <el-pagination
      v-model:current-page="paginationData.pageNum"
      :page-size="paginationData.pageSize"
      layout="total, prev, pager, next"
      :total="tableData.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script setup>
import { onMounted, reactive } from "vue";
import { adminOrder } from "../../../api/other";
import { useRoute, useRouter } from "vue-router";
import dayjs from "dayjs";
import { Plus, Check, InfoFilled, Delete } from "@element-plus/icons-vue";
const paginationData = reactive({
  pageNum: Number(1), // 显式转换为数字
  pageSize: Number(10), // 显式转换为数字
});
const tableData = reactive({
  list: [],
  total: 0,
});
//分页数据

const handleSizeChange = (val) => {
  paginationData.pageSize = val;
  getListData();
};
const handleCurrentChange = (val) => {
  paginationData.pageNum = val;
  getListData();
};
const getListData = (params = {}) => {
  adminOrder({ ...paginationData, ...params }).then(({ data }) => {
    const { list, total } = data.data;
    tableData.list = list;
    tableData.total = total;
  });
};
onMounted(() => {
  getListData();
});
// 订单状态
const stateMap = (key) => {
  const obj = {
    已取消: "info",
    待支付: "warning",
    已完成: "success",
  };
  return obj[key];
};
//表单搜索
const searchForm = reactive({
  out_trade_no: "",
});
// 查询
const onSubmit = () => {
  getListData(searchForm);
};
const confirmEvent = () => {};
</script>
<style scoped>
.form {
  display: flex;
  justify-content: flex-end;
  padding: 10px 0 10px 0;

  background-color: #fff;
}
</style>
